/**
 * Created by Admin on 2018/1/24.
 */
define(function (require, exports, module) {
    var template = require("template");
    var loadingTpl = require("./common/tpl/loading.html");
    require("./common/highchart/highcharts");
    require("./common/highchart/columnChart");
    require("./common/highchart/columnStackedChart");
    require("./common/highchart/columnStackedLineChart");
    require("./common/highchart/piechartsBasic");
    require("./common/highchart/linechartS");
    require("./common/highchart/basicchart");
    require("./common/highchart/pacInChart");
    require("./common/qy-template");
    require("./seajs-init");

    require("./common/highchart/piechart");

    var statTpl = require('./main/PatInfoStat.html');
    var tpl = require("./main/patInfo.html");

    // 原先的历年的转入转出
    function pacInAndOutBefore(data) {
        if (data.Moninfo.length > 0) {
            $("#transfer").show();
            var categories = [], yearIn = [], yearOut = [], total = [];
            for (var i = 0; i < data.Moninfo.length; i++) {
                categories.push(data.Moninfo[i].year);
                yearIn.push(data.Moninfo[i].in);
                //yearOut.push(-data.Moninfo[i].out);
                total.push(data.Moninfo[i].in, data.Moninfo[i].out);
            }
            var maxData = total[0];
            for (var i = 0; i < total.length; i++) {
                if (maxData < total[i]) {
                    maxData = total[i];
                }
            }
            maxData = Math.ceil(maxData);
            var sourceData = [
                {name: '转出', data: yearOut},
                {name: '转入', data: yearIn}
            ];
            var columnStackedLineChart = new ColumnStackedLineChart({
                dom: "transfer",
                xData: categories,
                yData: sourceData,
                maxData: maxData,
                legend: {
                    layout: 'top',
                    align: 'right',
                    floating: false
                },
                unit: "件"
            });

            $("#transfer").append('<p style="text-align:center;">历年专利转入转出对比</p>');
        } else {
            $("#transfer").append('<div class="nodata-title">暂无数据</div>');
            $(".la-square-jelly-box.la-2x").hide();
        }
    }

    // 新版的转入
    function pacInAndOutAfter(data) {
        if (data.Moninfo.length > 0) {
            var charData = [];
            var xData = [];
            for (var i = data.Moninfo.length - 1; i >= 0; i--) {
                xData.push(data.Moninfo[i].year.toString());
                charData.push([data.Moninfo[i].year.toString(), data.Moninfo[i].in])
            }
            createPacInChart({
                data: charData,
                name: '历年专利转入',
                title: '历年专利转入',
                yTitle: '专利(件数)',
                dom: 'transfer',
                xData: xData
            });
            $("#transfer").append('<p style="text-align:center;">历年专利转入</p>');
        } else {
            $("#transfer").append('<div class="nodata-title">暂无数据</div>');
            $(".la-square-jelly-box.la-2x").hide();
        }
    }


    var main = {
        init: function () {
            /*获取数据范围列表*/
            this.getList();
            /*专利总览*/
            // this.ptOverView();
            /*趋势分析----发明概况*/
            this.trendAnalysis(0);
            /*专利大户排名*/
            this.topParentRanking(1);
            /*专利监控*/
            this.patMonitor();
            /*万人专利授权指数*/
            this.millionValid("millionValid");
            /*万人发明专利授权指数*/
            this.millionValid("millionValidF");
            /*区域统计-有效专利*/
            this.areaStatisticValid();
            /*权利人分析柱形图*/
            // this.obAnalysisBar(1, "权利人数量分析");
            /*专利概况*/
            this.patentInfo();

            // 获取相关统计信息
            this.getIndexStat()

            this.patentStatInfo()
        },
        ptOverView: function () {
            $("#ptOverView").html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/pat",
                success: function (data) {
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0) {
                        /*遍历data的三个对象*/
                        var fmcount = [], syxxcount = [], wgsjcount = [], Name = ["专利总量", "当前有效专利", "今年新增公开", "今年新增授权"];
                        for (var key in data) {
                            if (key != "code") {
                                fmcount.push(data[key].fmcount);
                                syxxcount.push(data[key].syxxcount);
                                wgsjcount.push(data[key].wgsjcount);
                            }
                        }
                        var sourceData = [{name: '发明专利', data: fmcount},
                                {name: '实用新型', data: syxxcount},
                                {name: '外观专利', data: wgsjcount}],
                            //线形图初始化
                            linechart = new ColumnChart({
                                dom: "ptOverView",
                                xData: Name,
                                yData: sourceData,
                                legend: {
                                    layout: 'top',
                                    align: 'right',
                                    floating: false
                                }
                            });
                    } else {
                        $("#ptOverView").html('<div class="nodata-title">暂无数据</div>');
                    }
                }
            });
        },
        //乡镇统计概况
        patentInfo: function () {
            $.ajax({
                url: window.jkconfig.webapiurlv + "analysis/areaAnalysis/all",
                success: function (data) {
                    var piedata = [];
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0 && data.infos != null && data.infos.length > 1) {
                        $("#Js_statisticalBox").show();
                        $(".nodata-title").hide();
                        var html = template.compile(tpl)({data: data, keyName: "areaName"})
                        $("#validptchart-tab").html(html);
                        // 乡镇跳转
                        addCountryRedirct()


                        for (var i = 1, Name = ['合计'], fmcount = [], syxxcount = [], wgsjcount = []; i < data.infos.length; i++) {
                            Name.push(data.infos[i]["areaName"]);
                            fmcount.push(data.infos[i].fmcount);
                            syxxcount.push(data.infos[i].syxxcount);
                            wgsjcount.push(data.infos[i].wgsjcount);
                        }
                        // var sourceData = [{name: '发明专利', data: fmcount},
                        //     {name: '实用新型', data: syxxcount},
                        //     {name: '外观专利', data: wgsjcount}
                        // ];
                        /*subtitle数组*/
                        /*用于记录合计*/
                        var totalA = [];
                        $.each($(".totaleC"), function () {
                            totalA.push($(this).text());
                        });
                        if (typeof(totalA[0]) == "undefined") {
                            totalA[0] = 0;
                        }

                        for (var i = 0; i < data.infos.length; i++) {
                            var middleData = [];
                            middleData[0] = {name: '发明专利', y: data.infos[i].fmcount};
                            middleData[1] = {name: '实用新型', y: data.infos[i].syxxcount};
                            middleData[2] = {name: '外观专利', y: data.infos[i].wgsjcount};
                            piedata.push(middleData);
                        }
                        var piedtitle = "合计",
                            pietitle = piedtitle,
                            subtitle = "共" + totalA[0] + "件",
                            newPieChart = new PieChart({//饼图初始化
                                dom: "areaChart",
                                piedata: piedata,
                                pietitle: pietitle,//饼图一级标题
                                subtitle: subtitle,//饼图二级标题，
                                titleY: 40,
                                subtitleY: 60,
                                pieSize: 160
                            }),
                            valChartTab = $("#validptchart-tab tr");//饼状图改变容器
                        new PieChange2(valChartTab, false, true, newPieChart, totalA, pietitle, "所有区域", piedata);
                    } else {
                        $("#ptamountchart").html('<div class="nodata-title" style="height:270px;line-height:270px;">暂无数据</div>');
                        $("#Js_statisticalBox").hide();
                        $(".nodata-title").show();
                    }
                }
            });
        },
        //专利概况
        patentStatInfo: function () {
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/indexStatTotal",
                success: function (data) {
                    var piedata = [];
                    // $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0 && data.infos != null && data.infos.length > 1) {
                        // $("#Js_statisticalBox").show();
                        $(".n-1").hide();
                        var html = template.compile(statTpl)({data: data})
                        $("#staticChart-table").html(html);
                        for (var i = 0; i < data.infos.length; i++) {
                            var middleData = [];
                            middleData[0] = {name: '发明专利', y: data.infos[i].fmCount};
                            middleData[1] = {name: '实用新型', y: data.infos[i].syCount};
                            middleData[2] = {name: '外观专利', y: data.infos[i].wgCount};
                            piedata.push(middleData);
                        }
                        var totalArray = data.infos.map(function (v, i) {
                            return v.total
                        });
                        var piedtitle = "" && "合计",
                            pietitle = piedtitle,
                            subtitle = "共" + totalArray[0] + "件",
                            newPieChart = new PieChart({//饼图初始化
                                dom: "staticChart",
                                piedata: piedata,
                                pietitle: pietitle,//饼图一级标题
                                subtitle: subtitle,//饼图二级标题，
                                height: 160,
                                subtitleY: 3

                            }),
                            valChartTab = $("#staticChart-table tr");//饼状图改变容器
                        new PieChange2(valChartTab, false, true, newPieChart, totalArray, pietitle, "所有区域", piedata);
                        detailRedirct()
                    } else {
                        $(".n-1").show();
                    }
                }
            });
        },
        trendAnalysis: function (type) {
            $("#trendAnalysis").html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/trend/" + type,
                success: function (data) {
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0) {
                        if (data.infos.length > 0) {
                            /*遍历data的三个对象*/
                            var sdata = [];
                            var xData = [];
                            for (var i = data.infos.length - 1; i > 0; i--) {
                                xData.push(data.infos[i].year + "年");
                                sdata.push(data.infos[i].total);
                            }
                            var title = (type == 0 ? "历年申请专利趋势图" : "历年授权专利趋势图");
                            var linetitleD = (type == 0 ? "统计近十年的专利申请总量。" : "统计近十年已授权的专利总量。");
                            var sourceData = [{
                                name: title,
                                data: sdata
                            }];
                            var linechart = new LineChart({
                                dom: "trendAnalysis",
                                xData: xData,
                                yData: sourceData,
                                linetitle: title,
                                linetitleD: linetitleD,
                                linetitleDClass: "p-t-question-chart",
                                enabled: false,
                            })
                        } else {
                            $("#trendAnalysis").html('<div class="nodata-title">暂无数据</div>');
                        }
                    } else {
                        $("#trendAnalysis").html('<div class="nodata-title">暂无数据</div>');
                    }
                }
            })
        },
        getList: function () {
            $.ajax({
                url: window.jkconfig.webapiurlv + "analysis/dataType",
                success: function (data) {
                    var dataHtml = "", obHtml = "";
                    if (data.code == 0) {
                        /*在遍历data.DataTypeInfo,获取数据范围列表*/
                        if (data.DataTypeInfo.length > 0) {
                            for (var i = 0; i < data.DataTypeInfo.length; i++) {
                                dataHtml += '<option value="' + eval(data.DataTypeInfo[i].dataTypeValue) + '">' + data.DataTypeInfo[i].dataTypeName + '</option>';
                                if (data.DataTypeInfo[i].dataTypeName != "今年公开量" && data.DataTypeInfo[i].dataTypeName != "今年授权量") {
                                    obHtml += '<option value="' + eval(data.DataTypeInfo[i].dataTypeValue) + '">' + data.DataTypeInfo[i].dataTypeName + '</option>';
                                }
                            }
                            $("#TopParent").html(dataHtml);
                            $("#obDataType").html(obHtml);
                        }
                    } else {
                        $.showErr("获取数据范围列表失败!");
                    }
                }
            })
        },
        // 专利大户排名
        topParentRanking: function (type) {
            $("#topParentRanking").html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/rank/" + type,
                success: function (data) {
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0) {
                        var xData = [], fmcount = [], syxxcount = [], wgsjcount = [];
                        if (data.infos.items.length > 0) {
                            for (var i = 0; i < data.infos.items.length; i++) {
                                xData.push(data.infos.items[i].applicantName);
                                fmcount.push(data.infos.items[i].fmcount);
                                syxxcount.push(data.infos.items[i].syxxcount);
                                wgsjcount.push(data.infos.items[i].wgsjcount);
                            }
                            var sourceData = [{name: '发明专利', data: fmcount},
                                    {name: '实用新型', data: syxxcount},
                                    {name: '外观专利', data: wgsjcount}],
                                //线形图初始化
                                linechart = new ColumnStackedChart({
                                    dom: "topParentRanking",
                                    xData: xData,
                                    yData: sourceData,
                                    legend: {
                                        layout: 'top',
                                        align: 'right',
                                        floating: false
                                    },
                                    unit: "件",
                                    height: 350
                                });
                        } else {
                            $("#topParentRanking").append('<div class="nodata-title">暂无数据</div>');
                        }
                    } else {
                        $("#topParentRanking").append('<div class="nodata-title">暂无数据</div>');
                    }
                }
            });
        },
        // 历年专利转入转出对比
        patMonitor: function () {
            $("#transfer,#failCause").html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/patMon",
                success: function (data) {
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0) {
                        /*历年专利转入转出对比*/
                        //pacInAndOutBefore(data);
                        pacInAndOutAfter(data);
                        /*失效专利原因分析*/
                        if (data.expiryPatInfos.length > 0) {
                            $("#failCause").show();
                            var piedata = [], middleData = [];
                            for (var i = 0; i < data.expiryPatInfos.length; i++) {
                                middleData.push({
                                    name: data.expiryPatInfos[i].reason,
                                    y: data.expiryPatInfos[i].count / data.sum * 10000 / 100
                                });
                            }
                            piedata.push(middleData);
                            var pietitle = "失效专利原因分析",
                                newPieChart = new PieChartBasic({//饼图初始化
                                    dom: "failCause",
                                    piedata: piedata,
                                    pietitle: pietitle,//饼图一级标题,
                                    bgColor: "#fff",
                                    height: 250

                                });
                            if ($(".invalid-info").length <= 0) {
                                $("#failCause").append('<p class="invalid-info" style="text-align:center;">失效专利原因分析</p>');
                            }

                        } else {
                            $("#failCause").html('<div class="nodata-title">暂无数据</div>');
                            $(".la-square-jelly-box.la-2x").hide();
                        }
                    } else {
                        $("#transfer,#failCause").html('<div class="nodata-title">暂无数据</div>');
                    }
                }
            });
        },
        millionValid: function (dom) {
            $("#" + dom).html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/wryx",
                success: function (data) {
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0) {

                        $(".yxfmcount").html(data.Indicator.yxfmcount ? data.Indicator.yxfmcount + "件" : 0);
                        $(".population").html(data.Indicator.population ? data.Indicator.population + "万" : 0);
                        $(".yxfmWRCount").html(data.Indicator.yxfmWRCount ? data.Indicator.yxfmWRCount + "件" : 0);
                        if (data.monthinfo.length > 0) {
                            /*遍历data的三个对象*/
                            var sData = [], xData = [];
                            for (var i = 0; i < data.monthinfo.length; i++) {
                                sData.push(data.monthinfo[i].yxfmWRCount);
                                xData.push(data.monthinfo[i].month);
                            }
                            var title = new Date().getFullYear() + "年万人发明专利拥有量";
                            var sourceData = [{
                                name: title,
                                data: sData
                            }];
                            var linechart2 = new LineChart({
                                dom: dom,
                                xData: xData,
                                yData: sourceData,
                                linetitle: title,
                                enabled: false,
                                dataIndicator: data.monthinfo
                            })
                        } else {
                            $("#" + dom).append('<div class="nodata-title">暂无数据</div>');
                        }
                    } else {
                        $("#" + dom).append('<div class="nodata-title">暂无数据</div>');
                    }
                }
            })
        },
        areaStatisticValid: function () {
            $("#areaStatisticValid").html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/area",
                success: function (data) {
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0) {
                        $(".areaCount").html(data.count ? data.count : 0);
                        if (data.info.length > 0) {
                            /*遍历data的三个对象*/
                            var fmcount = [], syxxcount = [], wgsjcount = [], areaName = [];
                            for (var i = 0; i < data.info.length; i++) {
                                if (data.info[i].areaName == "未分类") {
                                    if (data.info[i].fmcount == 0 && data.info[i].syxxcount == 0 && data.info[i].wgsjcount == 0) {
                                        continue;
                                    }
                                } else if (data.info[i].areaName == "合计") {
                                    continue;
                                }
                                else {
                                    fmcount.push(data.info[i].fmcount);
                                    syxxcount.push(data.info[i].syxxcount);
                                    wgsjcount.push(data.info[i].wgsjcount);
                                    areaName.push(data.info[i].areaName);
                                }
                            }
                            var sourceData = [{name: '发明专利', data: fmcount},
                                    {name: '实用新型', data: syxxcount},
                                    {name: '外观专利', data: wgsjcount}],
                                //线形图初始化
                                linechart = new ColumnChart({
                                    dom: "areaStatisticValid",
                                    xData: areaName,
                                    yData: sourceData,
                                    height: 315
                                });
                        } else {
                            $("#areaStatisticValid").html(' <div class="nodata-title">暂无数据</div>');
                        }
                    } else {
                        $("#areaStatisticValid").html(' <div class="nodata-title">暂无数据</div>');
                    }
                }
            });
        },
        obAnalysisBar: function (type, patStr) {
            $("#obAnalysisBar1,#obAnalysisPie").html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/applyperson/" + type,
                success: function (data) {
                    $(".la-square-jelly-box.la-2x").hide();
                    if (data.code == 0) {
                        <!--权利人、权利人专利数量分析柱形-->
                        if (data.info.length > 0) {
                            var categories = [], applyPersonCount = [], applyPersonPatCount = [], total = [],
                                ApplyPersonSum = 0, ApplyPersonPatSum = 0;
                            for (var i = 0; i < data.info.length; i++) {
                                categories.push(data.info[i].applyPersonType);
                                applyPersonCount.push(data.info[i].applyPersonCount);
                                applyPersonPatCount.push(data.info[i].applyPersonPatCount);
                                total.push(data.info[i].applyPersonCount, data.info[i].applyPersonPatCount);
                                ApplyPersonSum += data.info[i].applyPersonCount;
                                ApplyPersonPatSum += data.info[i].applyPersonPatCount;
                            }
                            var maxData = total[0];
                            for (var i = 0; i < total.length; i++) {
                                if (maxData < total[i]) {
                                    maxData = total[i];
                                }
                            }
                            maxData = Math.ceil(maxData);
                            var sourcePersonData = [{name: '权利人数量', data: applyPersonCount}];
                            var sourcePatData = [{name: '权利人专利数量', data: applyPersonPatCount}];
                            var linechart1 = new BasicChart({
                                dom: "obAnalysisBar1",
                                xData: categories,
                                yData: sourcePersonData,
                                maxy: maxData,
                                reversed: true,
                                color: ["#199ED8"],
                                xEnabled: true
                            });
                            // 线形图初始化
                            var linechart2 = new BasicChart({
                                dom: "obAnalysisBar2",
                                xData: {
                                    title: {text: null}
                                },
                                yData: sourcePatData,
                                maxy: maxData,
                                color: ["#DF8161"],
                                xEnabled: false
                            });
                            /*饼图*/
                            var piedata = [], middleData = [];
                            for (var i = 0; i < data.info.length; i++) {
                                if (patStr == "权利人数量分析") {

                                    middleData.push({
                                        name: data.info[i].applyPersonType,
                                        y: Math.round(data.info[i].applyPersonCount / ApplyPersonSum * 100) / 100 * 100
                                    });
                                } else {
                                    middleData.push({
                                        name: data.info[i].applyPersonType,
                                        y: Math.round(data.info[i].applyPersonPatCount / ApplyPersonPatSum * 100) / 100 * 100
                                    });
                                }
                            }
                            /*没有数据*/
                            if (middleData.join("") === "") {
                                $("#obAnalysisBar1,#obAnalysisPie").html('<div class="nodata-title">暂无数据</div>');
                            } else {
                                piedata.push(middleData);
                                var newPieChart = new PieChartBasic({//饼图初始化
                                    dom: "obAnalysisPie",
                                    piedata: piedata,
                                    pietitle: "",//饼图一级标题,
                                    bgColor: "#fff"
                                });
                            }
                        } else {
                            $("#obAnalysisBar").html('<div class="nodata-title">暂无数据</div>');
                        }
                    } else {
                        $("#obAnalysisBar1,#obAnalysisPie").html('<div class="nodata-title">暂无数据</div>');
                    }
                }
            });
        },
        // 获取首页统计信息
        getIndexStat: function () {
            $.ajax({
                url: window.jkconfig.webapiurlv + "home/indexStat",
                success: function (data) {
                    if (data.code == 0) {
                        $('.index-main-td-count').each(function () {
                            var $self = $(this);
                            var name = $self.attr('data-name');
                            $self.text(data.info[name].toString() + (name === 'population' ? '万人' : '件'));
                        })
                    }
                }
            })
        }
    }

    main.init();

    $(function () {
        $("#trendListMenu").change(function () {
            main.trendAnalysis($(this).val());
        })
        $("#TopParent").change(function () {
            main.topParentRanking($(this).val());
        })
        $("#obDataType").change(function () {
            main.obAnalysisBar($(this).val(), $(".obligeeBox li.selected").html());
        })
        $("body").on("click", ".obligeeBox li", function () {
            $(this).addClass("selected").siblings("li").removeClass("selected");
            main.obAnalysisBar($("#obDataType").val(), $(this).html());
        }).on("click", ".btnDeal", function () {
            localStorage["areaId"] = $(this).attr("data-areaId");
            window.parent.location = "/#system/obligeeManage.html";
        })
    })

    // 专利概况 所有专利跳转
    function detailRedirct() {
        var redirectUrl = '/index.html#/analysis/patSearch.html'
        $('#staticChart-table tr').each(function (i, item) {
            var $self = $(this);
            var callback1 = null;
            var callback2 = null;
            switch (i) {
                case 0:
                    callback1 = function () {
                        localStorage.setItem("patHubTypeName", JSON.stringify(['发明公开', '发明授权']));
                    };
                    iterateTd($self, callback1)
                    break;
                case 1:
                    callback1 = function () {
                        localStorage.setItem("patHubTypeName", JSON.stringify(['发明授权']));

                    };
                    callback2 = function () {
                        localStorage.setItem("lawState", JSON.stringify([1]));
                    };

                    iterateTd($self, callback1, callback2)
                    break;
                case 2:
                    callback1 = function () {
                        localStorage.setItem("patHubTypeName", JSON.stringify(['发明授权']));

                    };
                    callback2 = function () {
                        localStorage.setItem("patAppDateBegin", new Date().getFullYear().toString() + '-01-01');
                        localStorage.setItem("patAppDateEnd", new Date().getFullYear().toString() + '-12-31');
                        localStorage.setItem("lawState", JSON.stringify([1]));
                    }

                    iterateTd($self, callback1, callback2);

                    break;
                default:
                    break
            }

        });

        function iterateTd($selector, callback1, callback2) {
            $('td', $selector).each(function (i, item) {
                switch (i) {
                    case 1:
                        $(this).on('click', function () {
                            window.top.location.href = redirectUrl
                            callback1 && callback1();
                            callback2 && callback2();
                        });
                        break;
                    case 2:
                        $(this).on('click', function () {
                            localStorage.setItem("patHubTypeName", JSON.stringify(['实用新型']));
                            callback2 && callback2();
                            window.top.location.href = redirectUrl
                        });

                        break;
                    case 3:
                        $(this).on('click', function () {
                            localStorage.setItem("patHubTypeName", JSON.stringify(['外观设计']));
                            callback2 && callback2();
                            window.top.location.href = redirectUrl
                        });

                        break;
                    case 4:
                        break;
                    default:
                        break;
                }

            })
        }


        // 公开发明
        $(document).on('click', '[data-name=dqgkfmCount]', function () {
            localStorage.setItem("lawState", JSON.stringify([5]));
            window.top.location.href = redirectUrl
        });
        // 实质审查
        $(document).on('click', '[data-name=szscCount]', function () {
            localStorage.setItem("lawState", JSON.stringify([3]));
            window.top.location.href = redirectUrl
        });
        // 有效发明
        $(document).on('click', '[data-name=yxfmCount],[data-name=fmzlsqCount]', function () {
            localStorage.setItem("patHubTypeName", JSON.stringify(['发明授权']));
            localStorage.setItem("lawState", JSON.stringify([1]));
            window.top.location.href = redirectUrl
        });
        // 实用新型授权
        $(document).on('click', '[data-name=syzlsqCount]', function () {
            localStorage.setItem("patHubTypeName", JSON.stringify(['实用新型']));
            localStorage.setItem("lawState", JSON.stringify([1]));
            window.top.location.href = redirectUrl
        });
        // 外观专利授权
        $(document).on('click', '[data-name=wgzlsqCount]', function () {
            localStorage.setItem("patHubTypeName", JSON.stringify(['外观设计']));
            localStorage.setItem("lawState", JSON.stringify([1]));
            window.top.location.href = redirectUrl
        });

    }

    function addCountryRedirct() {
        var redirectUrl = '/index.html#/analysis/patSearch.html'
        $("#validptchart-tab").on('click', '[fa]', function () {
            var areaId = $(this).attr('data-area-id')
            if(areaId!=-2){
                localStorage.setItem("patHubTypeName", JSON.stringify(['发明公开', '发明授权']));
            }

            if (areaId != 0) {
                if (areaId == -1) {
                    areaId = 0
                }
                localStorage.setItem("areaId", areaId)
            }

            window.top.location.href = redirectUrl
        })
        $("#validptchart-tab").on('click', '[sy]', function () {
            var areaId = $(this).attr('data-area-id')
            if(areaId!=-2){
                localStorage.setItem("patHubTypeName", JSON.stringify(['实用新型']));
            }

            if (areaId != 0) {
                if (areaId == -1) {
                    areaId = 0
                }
                localStorage.setItem("areaId", areaId)
            }

            window.top.location.href = redirectUrl
        })
        $("#validptchart-tab").on('click', '[wg]', function () {
            var areaId = $(this).attr('data-area-id')
            if(areaId!=-2){
                localStorage.setItem("patHubTypeName", JSON.stringify(['外观设计']));
            }
            if (areaId != 0) {
                if (areaId == -1) {
                    areaId = 0
                }
                localStorage.setItem("areaId", areaId)
            }

            window.top.location.href = redirectUrl
        })
    }

});